package com.example.xy_assistant;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.SimpleAdapter;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

import com.example.xy_assistant.adapter.NavAdapter;
import com.example.xy_assistant.bean.Nav;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class MainActivity extends AppCompatActivity {
    private long time;
    private GridView grid_view;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
        initData();
    }

    @Override
    public void onBackPressed() {
        long l = System.currentTimeMillis();
        if (l - time >= 2000) {
            Toast.makeText(this, "请再按一次退出！", Toast.LENGTH_SHORT).show();
            time = l;
        } else {
            super.onBackPressed();
        }
    }

    private void initView() {
        grid_view = (GridView) findViewById(R.id.grid_view);
    }

    private void initData() {
        List<Nav> navs = new ArrayList<>();
        navs.add(new Nav("学院简介", R.drawable.a01, R.color.nav_1));
        navs.add(new Nav("校园风光", R.drawable.a02, R.color.nav_2));
        navs.add(new Nav("校园电话", R.drawable.a03, R.color.nav_3));
        navs.add(new Nav("随手记", R.drawable.a04, R.color.nav_4));
        navs.add(new Nav("成绩查询", R.drawable.a05, R.color.nav_5));
        navs.add(new Nav("音乐播放", R.drawable.a06, R.color.nav_6));

        NavAdapter navAdapter = new NavAdapter(this, navs);
        grid_view.setAdapter(navAdapter);
        grid_view.setOnItemClickListener((parent, view, position, id) -> {
            Class c = null;
            switch (position) {
                case 0:
                    c = IntroActivity.class;
                    break;
                case 1:
                    c = PictureActivity.class;
                    break;
                case 2:
                    c = TelActivity.class;
                    break;
                case 3:
                    c = NoteActivity.class;
                    break;
                case 4:
                    c = ScoreActivity.class;
                    break;
                case 5:
                    c = MusicActivity.class;
                    break;
            }
            Intent intent = new Intent(MainActivity.this, c);
            startActivity(intent);
        });
    }
}